package com.example.natatorium_management.contorller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.natatorium_management.entity.MemberShip;
import com.example.natatorium_management.result.restful.R;
import com.example.natatorium_management.service.MemberShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/MemberShip")
public class MemberShipController {
    @Autowired
    MemberShipService memberShipService;

    /**
     * 新增会员
     * @param memberShip   1
     * @return 1
     */
    @PostMapping("/addMemberShip")
    public R<MemberShip> addMemberShip(@RequestBody MemberShip memberShip){
        return memberShipService.addMemberShip(memberShip);
    }

    /**
     * 分页查询所有
     * @param current 1
     * @param size 1
     * @return 1
     */
    @GetMapping("/queryPage")
    public R<IPage<MemberShip>> queryPage(int current, int size){
        return memberShipService.queryPage(current,size);
    }

    /**
     * 更新会员
     * @param memberShip 1
     * @return 1
     */
    @PutMapping("/updateMemberShip")
    public R<MemberShip> updateMemberShip(@RequestBody MemberShip memberShip){
        return memberShipService.updateMemberShip(memberShip);
    }

    /**
     * 根据id找会员
     * @param memberShipId 1
     * @return 1
     */
    @GetMapping("/findMemberShipById/{memberShipId}")
    public R<MemberShip> findMemberShipById(@PathVariable("memberShipId") int memberShipId){
        return memberShipService.findMemberShipById(memberShipId);
    }

    /**
     * 根据条件查询
     * @param memberShip 1
     * @return 1
     */
    @PostMapping("/findMemberShip")
    public R<IPage<MemberShip>> findMemberShip(@RequestBody MemberShip memberShip,@RequestParam int current,@RequestParam int size){
        return memberShipService.findMemberShip(memberShip,current,size);
    }

    /**
     * 根据id删除
     * @param memberShipId 1
     * @return 1
     */
    @DeleteMapping("/deleteMemberShipById")
    public R<MemberShip> deleteMemberShipById(int memberShipId){
        return memberShipService.deleteMemberShipById(memberShipId);
    }
}
